package com.example.task1.ui.AllService.movies;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;

import com.example.task1.R;
import com.example.task1.bean.MoviesSeatBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class MoviesSeatAdapter extends BaseAdapter<MoviesSeatBean.DataDTO> {

    private List<MoviesSeatBean.DataDTO> data = new ArrayList<>();
    private Button tvSeat;
    private OnSelectItem onSelectItem;

    public interface OnSelectItem {
        void Item(MoviesSeatBean.DataDTO date,int position,myHolder holder);
    }

    public void setOnSelectItem(OnSelectItem onSelectItem) {
        this.onSelectItem = onSelectItem;
    }

    @Override
    protected void setData(List<MoviesSeatBean.DataDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.moviesseatlist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<MoviesSeatBean.DataDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, MoviesSeatBean.DataDTO date) {

    }

    @Override
    protected void onBind(myHolder holder, MoviesSeatBean.DataDTO date, int position) {
        tvSeat.setText(date.getRow() + "排" + date.getCol() + "列");
        tvSeat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onSelectItem.Item(date,position,holder);
            }
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        tvSeat = (Button) itemView.findViewById(R.id.tv_seat);
    }
}
